<?php
/**
 * User: aka
 * Time: 20:29
 */

namespace app\http\middleware;

use app\tenno\model\GoodsEntry;
use think\Request;

class CatCheck
{
    private $account = 'blackCat';
    private $password = 'hb652229';

    public function __destruct()
    {
        unset(
            $this->account,
            $this->password
        );
    }

    public function handle(Request $request, \Closure $next)
    {
        $catAccount = base64_decode($request->param('account'));
        $catPassword = base64_decode($request->param('password'));
        $postName = $request->param('name');
        $condition = array();
        $condition['name'] = $postName;
        $sameGoodsEntry = GoodsEntry::where($condition)->find();
        if ($catAccount == $this->account && $catPassword == $this->password)
        {
            if (empty($sameGoodsEntry))
            {
                return $next($request);
            }else{
                return json('黑猫，'.$postName.' 这项词条你已经提交过了！');
            }
        }else{
            return json('你不是黑猫！别捣乱！或者你是不是某一项输入错误?');
        }
    }
}